﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>抽奖活动发布</title>
<!-- InstanceEndEditable -->

<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
	<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/ajaxfileupload.js"></script> 
<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
<script type="text/javascript" src="../js/editor.js"></script> 
	<script charset="utf-8" src="../js/kindeditor.js"></script>
	<script charset="utf-8" src="../js/lang/zh_CN.js"></script>
	<link href="../css/style.css" type="text/css" rel="stylesheet" />

<script type="text/javascript">
var prizeNeedlevelId = 0;
$(function(){
	refreshInput($(".serWrapper"));
	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
			$("#research").attr("disabled",false);
			
		}else{
			$("#shopName").attr("disabled",true);

		}
	});

	$('.doubledate').kuiDate({
		className:'doubledate',
		isDisabled: "1"  // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	resetForm();
	
	$("#swpType").change(function(){
		if($(this).val()==1){
			$(".partNum").show();
		}else{
			$(".partNum").hide();
		}
	})
	browse('upload','imgSrc',100,100);
	
});
</script>
<script type="text/javascript">
var pageIndex=1;
var prizeIndex=1;
var pageCount=0;
var pagecount=0;
var shopPageIndex=0;
var shopCount=0;
var array=new Array();
var existPrizeLvId= new Array();
$(function(){
	
	$.ajax({
		url:'../prizelevel/find/prizelvList',
		datatype:'json',
		type:'get',
		success:
			function(data){
			var rst= JSON.parse(data);
			if(rst.state==0){	
				loadPrizeLeveTable(rst)
			}
		}
	})
	
	$("input[type='file']").change(function(){
		$(this).prev().prev().val($(this).val())
	})
	
	$("#closeThe").click(function(){
		$("#windowPop,#yinying1").hide();
	})
	
	
	
	
	
	
	$("#closeThis").click(function(){
				$("#PopList").hide();
				$("#yinying1").css("z-index",100);
			})
	
})

PageClick = function(pageclickednumber) {
	pageIndex=pageclickednumber;
	findSweepstakesList();
}


function uploads(id,content){
	$.ajaxFileUpload({
		url :"../sweepstakes/upload/image/indexImage/"+id,
		secureuri : false,
		fileElementId : 'upload',
		dataType : 'json',
		success : function(data){
			if (data.state == 0) {
				pageIndex=1;
				findSweepstakesList();
				resetForm();
				art.dialog({fixed:true, lock: true,content:content+"成功",icon:'succeed',ok:true});	

				$("#yinying1,#content").hide();
				return true;
			} else{
				art.dialog({fixed:true, lock: true,content:data.msg,icon:'error',ok:true});	
			}
		},
		error : function(data) {

			art.dialog({fixed:true, lock: true,content:"图片上传失败",icon:'error',ok:true});	

			return false;
		}
	});
}

function toAdds(){
		$("#yinyingCenter,#windowPop").show();

}
function loadPrizeTable(json,prizelvId){
	
	$("#awardList tbody").empty();
	
	for(i=0;i<json.result.data.length;i++){
		$("#awardList tbody").append("<tr></tr>");
		var prizeId=getHeadIndexValue(i, json, "PrizeId");
		var htm="<td>"+getHeadIndexValue(i, json, "PrizeCode")+"</td>";
			htm+="<td>"+getHeadIndexValue(i, json, "PrizeName")+"</td>";
			htm+="<td><input type='button' class='common_btn' onclick='choosePrize("+prizeId+","+prizelvId+",$(this))' value='选择'></td>";
			
		$("#awardList tbody tr:last").append(htm)
	}
	
	addMargin($("#PopList"))
}

function savePrizeLvAndPrize(){
	
	var doType=$("#doType").val();
	if(doType=="1"){
		updatePrize();
		return false;
	}
	
	var length=$("input[type='checkbox'][class='prizeLvCheck']:checked").length
    var reg = new RegExp("^[1-9]\\d*$");
	array=new Array();
	if(IsNotEmpty(length)&&length>0){
		var addedPrizeId=new Array();
		var checkPrizeId=false;
		var checkNum=false;
		var flag=false;
		$("input[type='checkbox'][class='prizeLvCheck']:checked").each(function(){
			var prizeLvId= $(this).val().replace(/\s/gi,'');
			var prizeId=$(this).next("input").val().replace(/\s/gi,'');
			if(IsEmpty(prizeId)){
				flag=true;
			}
			var num=$(this).parents("tr").find("td:last").find("input").val().replace(/\s/gi,'')
		
			var winnerNum=$(this).parents("tr").find("td:eq(3)").find("input").val().replace(/\s/gi,'')
			if(!reg.test(winnerNum)){
				$(this).parents("tr").find("td:eq(3)").find("input").focus();
				checkNum=true;
			}
			if(!reg.test(num)){
				$(this).parents("tr").find("td:last").find("input").focus();
				checkNum=true;
			}
			for ( var i = 0; i < addedPrizeId.length; i++) {
				if(prizeId==addedPrizeId[i]){
					checkPrizeId=true;
				}
			}
			addedPrizeId.push(prizeId);
			
			var value=new Array();
			value.push(prizeLvId);
			value.push(prizeId);
			value.push(winnerNum);
			value.push(num);
			array.push(value);
		})
		if(checkPrizeId){
			art.dialog({fixed:true, lock: true,content:"奖品重复",icon:'error',ok:true});	
			return false;
		}
		if(checkNum){
			art.dialog({fixed:true, lock: true,content:"奖品数量错误",icon:'error',ok:true});	
			return false;
		}
		if(flag){
			art.dialog({fixed:true, lock: true,content:"请选择对应奖项奖品",icon:'error',ok:true});	
			return false
		}
		
		$("#windowPop,#yinyingCenter").hide();

		
	}else{
		art.dialog({fixed:true, lock: true,content:"请至少选择一个奖项",icon:'error',ok:true});	
		return false;
	}
}

function updatePrize(){
	var swpId=$("#updateSwpId").val();	
	var length=$("input[type='checkbox'][class='prizeLvCheck']:checked").length
    var reg = new RegExp("^[0-9]\\d*$");
	
	var parser2 = new Object();
	var alljson = null;
	var delJson = null;
	var addJson = null;
	var updteJson = null;
	var prizeIdArray=new Array()
	var flag= false;
	var checkNum =false;
	var checkPrizeId = false;
	if(IsNotEmpty(length)&&length>0){
		
		var addedPrizeId=new Array();
		$("input[type='checkbox'][class='prizeLvCheck']:checked").each(function(){
			var prizeLvId= $(this).val().replace(/\s/gi,'');
			var prizeId=$(this).next("input").val().replace(/\s/gi,'');
			var num=$(this).parents("tr").find("td:last").find("input").val().replace(/\s/gi,'')
			
			var winnerNum=$(this).parents("tr").find("td:eq(3)").find("input").val().replace(/\s/gi,'')
			if(!reg.test(winnerNum)){
				$(this).parents("tr").find("td:eq(3)").find("input").focus();
				checkNum=true;
			}
			if(!reg.test(num)){
				$(this).parents("tr").find("td:last").find("input").focus();
				checkNum=true;
			}
			if(IsEmpty(prizeId)||prizeId==null){
					flag=true;
			}	
		
			var type=0
			for ( var i = 0; i < existPrizeLvId.length; i++) {
				if(prizeLvId==existPrizeLvId[i]){
					type=1;
				}
			}
				
			var head=new Array("pId","winnersNum","num","plId","swpId")
			 var data=new Array(prizeId,winnerNum,num,prizeLvId,swpId)
			if(type==1){
				addToParser(head, data, "edit" , parser2);
				alljson=JSON.stringify(parser2)
			}else if(type==0){				
			addToParser(head, data, "add" , parser2);
			alljson = JSON.stringify(parser2) ;

			}
			
			for ( var i = 0; i < addedPrizeId.length; i++) {
				if(prizeId==addedPrizeId[i]){
					checkPrizeId=true;
				}
			}
			addedPrizeId.push(prizeId)
			
			})
			
		
		$("input[type='checkbox']:checkbox").not("input:checked").each(function(){
			var prizeLvId= $(this).val().replace(/\s/gi,'');
			for ( var i = 0; i < existPrizeLvId.length; i++) {

				if(prizeLvId==existPrizeLvId[i]){
					var head=new Array("plId","swpId")
					 var data=new Array(prizeLvId,swpId)
					if (IsNotEmpty(data)){
						addToParser(head, data, "del" , parser2);
						alljson =  JSON.stringify(parser2);
					}
				}
			}
		})
		
		if(checkPrizeId){
			art.dialog({fixed:true, lock: true,content:"奖品重复",icon:'error',ok:true});	
			return false;
		}
		if(checkNum){
			art.dialog({fixed:true, lock: true,content:"奖品数量错误",icon:'error',ok:true});	
			return false;
		}
		if(flag){
			art.dialog({fixed:true, lock: true,content:"请选择奖品",icon:'error',ok:true});	
			return false
		}
		$.post("../prizepackage/editPrize",{"data":alljson,"swpId":swpId}, function(data) {
			var dt = JSON.parse(data);
			if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"数据修改错误",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					$("#windowPop,#yinyingCenter").hide();

					 }else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:"数据修改错误",icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}	
			
		});
				
	}else{
		art.dialog({fixed:true, lock: true,content:"请至少选择一个奖项",icon:'error',ok:true});	
		return false;
	}
}
function choosePrize(prizeId,prizeLvId,obj){
	$("#prizeLv_"+prizeLvId).html(obj.parent().prev().html())
	$("#prizeLvPrize_"+prizeLvId).val(prizeId)
	$("#PopList").hide();
	$("#yinying1").css("z-index",100);
}
function showPrize(prizeLvId){
	prizeNeedlevelId = prizeLvId
	getAllPrize(1)
	
}

function getAllPrize(index){
	if(IsNotEmpty(index)){
		prizeIndex = index;
	}else{
		prizeIndex = 1;
	}
	var shopID =getInputValue("shopId");
	var params= {'shopId':shopID,'status':1}
	$.ajax({
		url:'../prize/find/prizeList/' +(prizeIndex -1)+'/10',
		datatype:'json',
		type:'get',
		data:params,
		success:
			function(data){
			var rst= JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询错误",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					if(rst.result.len>0){
						
						loadPrizeTable(rst,prizeNeedlevelId)
						var shu = rst.result.len;
						 var con = Math.ceil(shu/10);
						
						 $("#prizePage").pager({ pagenumber:prizeIndex, pagecount: con, buttonClickCallback: getAllPrize });

						}
					 }else if(rst.state==1){
							art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}		
			
			
		}
	})
	
	
	$("#PopList").show();
	$("#yinying1").css("z-index",300);
	addMargin($("#PopList"));//点击显示
}
function loadPrizeLeveTable(json){
	$("#awardDet tbody").empty();
	for(i=0;i<json.result.data.length;i++){
		$("#awardDet ").append("<tr></tr>");
		var prizeLvId=getHeadIndexValue(i, json, "prizeLvId");
		var htm="<td><input type='checkbox' class='prizeLvCheck' value='"+prizeLvId+"' style='width:auto;' > <input type='hidden' value='' id='prizeLvPrize_"+prizeLvId+"'> </td>";
			htm+="<td>"+getHeadIndexValue(i, json, "PrizeLvName")+"</td>";
			htm+="<td id='prizeLv_"+prizeLvId+"' class=\"newAward\" onclick='showPrize("+prizeLvId+")'><input type=\"button\" class=\"common_btn\" value='奖品设置'></td><td><input class=\"txt\" type=\"text\"></td><td><input class=\"txt\" type=\"text\"></td>";
			
		$("#awardDet tr:last").append(htm)
	}
	addMargin($("#windowPop"))
}

function save(){
	
	var doType=$("#doType").val();
	if(doType=="1"){
		var swpId = $("#updateSwpId").val()
		updateSwp(swpId);
		return false;
	}
	
	var prizeNum=array.length;
	if(prizeNum==0){
		art.dialog({fixed:true, lock: true,content:"请先选择奖项级别",icon:'error',ok:true});	
		
		return false;
	}
	
		var parser2 = new Object();
		var jsonParserStr2 = null;
	for ( var i = 0; i < array.length; i++) {
		var head=new Array("plId","pId","winnersNum","num")
		 var data=new Array(array[i][0],array[i][1],array[i][2],array[i][3])
		if (IsNotEmpty(data)){
			addToParser(head, data, "add" , parser2);
			jsonParserStr2 =  JSON.stringify(parser2);
		}
	}
	
	
	var swpName=$("#swpName").val().replace(/\s/gi,'');
	var beginTime=$("#beginTime").val().replace(/\s/gi,'');
	var endTime=$("#endTime").val().replace(/\s/gi,'');
	var swpContent=$("#swpContent").val().replace(/\s/gi,'');
	var swpType=$("#swpType").val();
	var shopName=$("#shopName2").val()
	var shopId=$("#shopId").val();
	var fileName=$("#upload").val();
	if(IsEmpty(fileName)){
		art.dialog({fixed:false, lock: true,content:"请选择图片",icon:'error',ok:true});	
		
		return false;
	}
	if(IsEmpty(swpName)){
		art.dialog({fixed:true, lock: true,content:"活动名称不能为空",icon:'error',ok:true});	
		return false;			
	}
	if(IsEmpty(beginTime)){
		art.dialog({fixed:true, lock: true,content:"活动起始不能为空",icon:'error',ok:true});	
		return false;			
	}
	if(IsEmpty(endTime)){
		art.dialog({fixed:true, lock: true,content:"活动截止不能为空",icon:'error',ok:true});	
		return false;			
	}

	if(IsEmpty(shopId)){
		art.dialog({fixed:true, lock: true,content:"请选择店铺",icon:'error',ok:true});	
		return false;			
	}
	if(IsEmpty(swpContent)){
		art.dialog({fixed:true, lock: true,content:"活动简介不能为空",icon:'error',ok:true});	
		return false;			
	}
	var partNum=null;
	if(swpType==1){
		partNum = $("#partNum").val()
	}
	
	var heads=new Array("name","content","swpBeginDate","swpEndDate","prizeTypeId","shopName","shopId","particNums")
	var datas=new Array(swpName,swpContent,beginTime,endTime,swpType,shopName,shopId,partNum)
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "add" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	
	
	$.post("../sweepstakes/insert",{"data":jsonParserStr,"prize":jsonParserStr2,"htmlStr":editorHtml}, function(data) {
		var dt = JSON.parse(data);
		if(IsEmpty(dt)){
			art.dialog({fixed:true, lock: true,content:"添加错误",icon:'error',ok:true});	
			return false;
			}
			if(dt.state==0){
			uploads(getHtmlInt(getHeadIndexValue(0, dt, "id")),"添加");
			
			}else if(dt.state==1){
						art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
			}else{
				checkStateShowErrorMsgAndDealResult(data);
			}	
		
	});
	
}

function findSweepstakesList(){
	var name=$("#searchSwName").val().replace(/\s/gi,'');	
	var subMan=$("#searchMan").val().replace(/\s/gi,'');
	var shopId="";
	var param=null;
	if($("#shopIsChoosed").is(":checked")){	
		shopId=$("#shopName").val();
		
		if(shopId!=""&&shopId!=null){
			param={'name':name,'submitMan':subMan,'status':'0','shopId':shopId}
		}else{
			param={'name':name,'submitMan':subMan,'status':'0'}	
		}
	}else{
		param={'name':name,'submitMan':subMan,'status':'0'}

	}
	$.ajax({
		url:'../sweepstakes/find/sweepstakesList/'+pageIndex+'/10',
		datatype:'json',
		data:param,
		type:'get',
		success:
			function(data){
			var rst= JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询数据错误",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					$("#sup").html("共："+rst.result.len+"条")
					loadtable(rst)
					 var shu = rst.result.len;
						pagecount = Math.ceil(shu/10);
						if(rst.result.len==0){
							$("#NoResult").show();
						}else{
							$("#NoResult").hide();
						}
					 $("#pager").pager({ pagenumber:pageIndex, pagecount: pagecount, buttonClickCallback: PageClick });

				}else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
			
		}
	})
}

function loadtable(rst){
	$("#rewardList tbody").empty();
	for(i=0;i<rst.result.data.length;i++){	
	var swpId=getHeadIndexValue(i, rst, "swptaksID");
	$("#rewardList tbody").append("<tr id='swp_"+swpId+"'></tr>");
	
	var htmlString="<td id='swpList_shopName_"+swpId+"'>"+getHeadIndexValue(i, rst, "shopName")+"</td>"
	htmlString+="<td id='swpList_swpName_"+swpId+"'>"+getHeadIndexValue(i, rst, "swptaksName")+"</td>"
	htmlString+="<td><img id='swpList_image_"+swpId+"' src='"+getHeadIndexValue(i, rst, "ImageURL")+"?time="+(new Date()).getTime()+"'></td>"
	htmlString+="<td id='swpList_beginTime_"+swpId+"'>"+getHeadIndexValue(i, rst, "swptaksBeginDate")+"</td>"
	htmlString+="<td id='swpList_endTime_"+swpId+"'>"+getHeadIndexValue(i, rst, "swptaksEndDate")+"</td>"
	htmlString+="<td id='swpList_swpType_"+swpId+"'> <input type='hidden' id='swpList_prizeTypeId_"+swpId+"' value='"+getHeadIndexValue(i, rst, "prizeTypeId")+"'> "+getHeadIndexValue(i, rst, "swpType")+"</td>"
	htmlString+="<td id='swpList_subman_"+swpId+"'>"+getHeadIndexValue(i, rst, "submitMan")+"</td>"
	htmlString+="<td id='swpList_subDate_"+swpId+"'>"+getHeadIndexValue(i, rst, "submitDate")+"</td>"
	htmlString+="<td id='swpList_swpContent_"+swpId+"' style='display:none;'>"+getHeadIndexValue(i, rst, "swptaksContent")+"</td>"
	htmlString+="<td id='swpList_do_"+swpId+"'><input type='hidden' id='swpList_shopId_"+swpId+"' value='"+getHeadIndexValue(i, rst, "shopId")+"'> <input onclick='update("+swpId+")' class=\"common_btn\" type=\"button\" value=\"修改\"><br><input onclick='popPoint("+swpId+")' class=\"del common_btn\" type=\"button\" value=\"删除\"> <input type='hidden' id='swpList_indexUrl_"+swpId+"' value='"+getHeadIndexValue(i,rst,"indexUrl")+"'/><input type='hidden' id='swpList_num_"+swpId+"' value='"+getHeadIndexValue(i,rst,"particNums")+"'/> </td>"
	$("#rewardList tbody tr:last ").append(htmlString)
	}
	

}

function deleteSwp(id){	
	if(IsNotEmpty(id)){

		$.post("../sweepstakes/del",{"id":id}, function(data) {
			var dt = JSON.parse(data);
			if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"删除数据错误",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					findSweepstakesList()
					art.dialog({fixed:true, lock: true,content:"删除成功",icon:'succeed',ok:true});	
				}else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
			
		});
	}
}



function InitShopList(shopPageIndex){
	var shopName=$("#searchName").val();
	$.ajax({
		type : "post",
		async:false,
		data :'name='+shopName,
		datatype : "json",
		url : "../shop/find/shopList/" + shopPageIndex + "/5",
		success : function(data) {
			var rst = JSON.parse(data);
			 if(IsEmpty(rst)){
					art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
					return false;
					}
					if(rst.state==0){
						$("#shopList tbody tr").remove();

						initShopTable(rst);
						$("table[id='shopList'] tbody tr").each(function(){
							$(this).children("td:last").css("text-align","center").append("<input type='button' class='common_btn' value='选择' onclick='bclicks($(this))'>");

						})	
						if(rst.result.len > 0){
							 var shu = rst.result.len;
							 shopCount = Math.ceil(shu/5);					
							 }else{
									shopCount==0;
							 }
						 $("#shopPager").pager({ pagenumber: ++shopPageIndex, pagecount: shopCount, buttonClickCallback: ShopPageClick });
						 addMargin($("#shopShow"));	
						 }else if(rst.state==1){
						art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}
					
		}	
	});	
	
}
ShopPageClick = function(pageclickednumber) {
    $("#shopPager").pager({ pagenumber: --pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
    $("#result").html("Clicked Page " + pageclickednumber);
    InitShopList(pageclickednumber);
}
function shopExits(id){
	var bloo=false
	$("#shopName").find("option").each(function(){
		
		if($(this).attr("value")===id){
			bloo= true;
			return bloo;
		}
	})
	return bloo;
}
function getParamToshopS(id,name){
	
	var shopflag=$("#shopflag").val();
	if(shopflag==1){
		var htm="<option value='"+id+"'>"+name+"</option>";
		$("#shopName").html(htm);
		$("#shopName").val(id);	
	}else{	
	$("#shopId").val(id);
	$("#shopName2").val(name);
	}
	closeShopShow();
}

function closeShopShow(){
	$("#shopShow,#yinying").hide();
	$("#searchName").val("")
}
function initShopTable(json){
	if(json!=null && json.state==0){
		var params = new Array("id", "name","mp","contact");
		Loadtable(json,params,"shopList");
	}
}


function Loadtable(json, params, tableId){
	var phArray = new Array();
	var count = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {
						$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d == "null" ? " " : d) + "</td>");
					}
				});
			});
		});
		
	}
	

	
}


function bclicks(obj){
	var $first=obj.parent("td").parent("tr").children("td:first");
	var id=$first.html();
	var name=$first.next().html();
	//$("#shopName").children("option").blur();
	getParamToshopS(id,name)
}

function update(swpId){
	var shopName= $("#swpList_shopName_"+swpId).html();
	var swpName= $("#swpList_swpName_"+swpId).html();
	var image= $("#swpList_image_"+swpId).attr("src");
	var beginTime= $("#swpList_beginTime_"+swpId).html();
	var endTime= $("#swpList_endTime_"+swpId).html();
	var swpType= $("#swpList_swpType_"+swpId).html();
	var subMan= $("#swpList_subman_"+swpId).html();
	var subContent= $("#swpList_swpContent_"+swpId).html();
	var shopId=$("#swpList_shopId_"+swpId).val();
	var prizeTypeId=$("#swpList_prizeTypeId_"+swpId).val();
	var indexUrl = $("#swpList_indexUrl_"+swpId).val()
	if(prizeTypeId==1){
	var num = $("#swpList_num_"+swpId).val()
		$("#partNum").val(num)
		$(".partNum").show()
	}
	$("#editorUrl").val(indexUrl);
	$("#shopName2").val(shopName);
	$("#picUrl").val(image)
	$("#shopId").val(shopId);
	$("#swpName").val(swpName);
	$("#imgSrc").html("<img src='"+image+"'/>");
	$("#beginTime").val(beginTime);
	$("#endTime").val(endTime);
	$("#swpP").val(subMan)
	$("#swpType").val(prizeTypeId)
	$("#swpContent").val(subContent);
	$("#save_btn").val("保存修改")
	$("#level").val("奖项修改")
	$("#shopId").val(shopId)
	
	$("#doType").val("1");
	$("#updateSwpId").val(swpId)
		$("#content,#yinying1").show();
	getHtmlByUrl(indexUrl);
		}
	function toAdd(){
		resetForm();
		var shopId= $("#shopName").val()
		if(IsEmpty(shopId)){
			artError("请先选择店面");
			return false;
		}
		var shopName = $("#shopName").text()
		$("#shopName2").val(shopName);
		$("#shopId").val(shopId);
		$("#content,#yinying1").show();
	
	}
	function updateSwp(swpId){
		
		var swpName=$("#swpName").val().replace(/\s/gi,'');
		var beginTime=$("#beginTime").val().replace(/\s/gi,'');
		var endTime=$("#endTime").val().replace(/\s/gi,'');
		var swpContent=$("#swpContent").val().replace(/\s/gi,'');
		var swpType=$("#swpType").val();
		var shopName=$("#shopName2").val()
		var shopId=$("#shopId").val();
		if(IsEmpty(swpName)){
			art.dialog({fixed:true, lock: true,content:"活动名称不能为空",icon:'error',ok:true});	
			return false;			
		}
		if(IsEmpty(beginTime)){
			art.dialog({fixed:true, lock: true,content:"活动起始不能为空",icon:'error',ok:true});	
			return false;			
		}
		if(IsEmpty(endTime)){
			art.dialog({fixed:true, lock: true,content:"活动截止不能为空",icon:'error',ok:true});	
			return false;			
		}

		if(IsEmpty(shopId)){
			art.dialog({fixed:true, lock: true,content:"请选择店铺",icon:'error',ok:true});	
			return false;			
		}
		if(IsEmpty(swpContent)){
			art.dialog({fixed:true, lock: true,content:"活动简介不能为空",icon:'error',ok:true});	
			return false;			
		}
		
		
		if(swpType==1){
			partNum = $("#partNum").val()
		var heads=new Array("particNums","name","content","swpBeginDate","swpEndDate","prizeTypeId","shopName","shopId","id")
		var datas=new Array(partNum ,swpName,swpContent,beginTime,endTime,swpType,shopName,shopId,swpId)
		}else{
			var heads=new Array("name","content","swpBeginDate","swpEndDate","prizeTypeId","shopName","shopId","id")
			var datas=new Array(swpName,swpContent,beginTime,endTime,swpType,shopName,shopId,swpId)
		}
		
		var parser = new Object();
		var jsonParserStr = null;
		if (IsNotEmpty(datas)){
			addToParser(heads, datas, "edit" , parser);
			jsonParserStr =  JSON.stringify(parser);
		}
		
		var fileName= $("#upload").val();
		$.post("../sweepstakes/edit",{"data":jsonParserStr,"htmlStr":editorHtml}, function(data) {
			var dt = JSON.parse(data);
			
			 if(IsEmpty(dt)){
					art.dialog({fixed:true, lock: true,content:"修改出错",icon:'error',ok:true});	
					return false;
					}
					if(dt.state==0){
						if(IsNotEmpty(fileName)){
							uploads(swpId,"修改");
						}else{
							art.dialog({fixed:true, lock: true,content:"修改成功",icon:'succeed',ok:true});	
						findSweepstakesList();
						resetForm();
						$("#content,#yinying1").hide();

						}	
						 }else if(dt.state==1){
								art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}	
			
		});
		
	}
	
	
	function toUpdatPrize(swpId){
		$.ajax({
			url:'../prizelevel/find/prizelvChecked',
			datatype:'json',
			data:'swpId='+swpId,
			type:'get',
			success:
				function(data){
				var rst= JSON.parse(data);
				 if(IsEmpty(rst)){
						art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
						return false;
						}
						if(rst.state==0){
							if(rst.result.len>0){
								$("#awardDet tbody").empty();
								existPrizeLvId=new Array()
								for(i=0;i<rst.result.data.length;i++){
									
									$("#awardDet ").append("<tr></tr>");
									var prizeLvId=getHeadIndexValue(i, rst, "prizeLvId");
									if(getHeadIndexValue(i, rst, 'checked')==='1'){
									existPrizeLvId.push(prizeLvId)
									}
									var prizeName=getHeadIndexValue(i, rst, 'checked')==='1'?getHeadIndexValue(i, rst, "PrizeName"):""
									var checked=getHeadIndexValue(i, rst, 'checked')==='1'?"checked='checked'":""
									var winnersNum=getHeadIndexValue(i, rst, 'checked')==='1'?getHeadIndexValue(i, rst, "winnersNum"):""
									var prizeId=getHeadIndexValue(i, rst, 'checked')==='1'?getHeadIndexValue(i, rst, "prizeId"):""
									var num=getHeadIndexValue(i, rst, 'checked')==='1'?getHeadIndexValue(i, rst, "num"):""
									var htm="<td><input type='checkbox' class='prizeLvCheck' "+checked+" value='"+prizeLvId+"'> <input type='hidden' value='"+prizeId+"' id='prizeLvPrize_"+prizeLvId+"'> </td>";
										htm+="<td>"+getHeadIndexValue(i, rst, "PrizeLvName")+"</td>";
										htm+="<td id='prizeLv_"+prizeLvId+"' class=\"newAward\" onclick='showPrize("+prizeLvId+")'>"+prizeName+" <a>奖品设置</a></td><td><input class=\"txt\" type=\"text\" value='"+winnersNum+"'></td><td><input class=\"txt\" type=\"text\" value='"+num+"'></td>";
										
									$("#awardDet tr:last").append(htm)
									$("#yinyingCenter,#windowPop").show();
									addMargin($("#windowPop"))

								}
							}
							 }else if(rst.state==1){
									art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
						}else{
							checkStateShowErrorMsgAndDealResult(data);
						}	
					addMargin($("#windowPop"))
				
			}
		})
	}
	function showShopList(shopflag){
		$("#shopflag").val(shopflag);
		$("#shopName").blur();
		$("#shopShow,#yinying").show();
		InitShopList(0);
	}
	function showPrizeLv(){
		var doType=$("#doType").val();
		if(doType=="1"){
			var swpId = $("#updateSwpId").val()
			toUpdatPrize(swpId);
			return false;
		}
		$("#yinyingCenter,#windowPop").show();
	}
	function resetForm(){
		$("#shopName2").val("");
		$("#shopId").val("");
		$("#swpName").val("");
		$("#imgSrc img").attr("src","../images/img_activities1.jpg");
		$("#beginTime").val("");
		$("#endTime").val("");
		$("#swpType").val(2);
		$(".pratNum").hide();
		$("#swpP").val("")
		$("#swpContent").val("");
		$("#save_btn").val("立即发布")
		$("#level").val("奖项设置")
		$("#shopId").val("")
		$("#doType").val("0")
		$("#upload").val("")
		$("#upload").prev().prev().val("")
		$("#editorUrl").val("");
		editorHtml = "";
		browse('upload','imgSrc',96,96);

	}
	
	
	function popPoint(id){
		art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){ deleteSwp(id)},cancel:true});
		}

</script>


</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 

<div id="yinying1"></div>
<div id="yinyingCenter"></div>
<div id="yinying"></div>
	<div id="shopShow" class="hideDiv">
	    <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="closeShopShow();" >X</span> </div>
	    <div class="bottom_search"><div class="serWrapper"><input type="text" id="searchName" class="txt"><strong class="refresh" onclick="$('#searchName').val('')">清空</strong></div><input class="common_btn" type="button" style="width:auto;margin-left:5px;" value="查询" onclick="search2()"></div>
	    <table   id="shopList" cellpadding="4" cellspacing="0" border="1" width="100%">
	    <thead>
	    <tr>
	    <th>店面ID</th>
	    <th>店面名称</th>
	    <th>电话</th>
	    <th>操作</th>
	    </tr>
	    </thead>
	    </table>
	    <div id="shopPager"></div>
    </div>
    <div class="member_search publish hideDiv" id="content">
    <div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
    <p><input type="button" id="level" value="奖项设置" onclick="showPrizeLv()"></p>
    	<input type="hidden" id="doType" value="0">
    	<input type="hidden" id="updateSwpId" >
    	<input type="hidden" id="shopflag">
       <form name="fm1" action="#" target="post">
            <p><span> 店面：</span><input type="text"  id="shopName2" readonly> <input type="hidden" id="shopId"> <input type="button" value="..." class="btn"  onclick="showShopList(2)" /></p>
            <p><span>活动名称：</span><input type="text" id="swpName"></p>
            <p><span>活动图片：</span><input type="text" id="picUrl"><input type="button"  value="..." class="btn"  /><input type="file" class="file" name="upload" id="upload" > <span id="imgSrc" class="onlyImgSrc actorImg"> <img  src=""> </span></p>
           <p><span>活动页面：</span> <input type="text" id="editorUrl"  class="reset" style="width: 300px;" readonly>
        <input type="button" class="btn"  value="编辑页面" id="editIndex_btn" style="font-size:12px;font-weight:normal;"></p>
            <p><span>起始日期：</span><input style="width: 150px;" type="text" class="doubledate" id="beginTime"  readonly="readonly">
            <span>截止日期：</span><input style="width: 150px;" type="text" class="doubledate" id="endTime" readonly></p>
            <p><span>抽奖类型：</span>
            <select id="swpType" style="width: 150px;">
           
            <option value="1">即时抽奖</option>
            <option value="2">后台抽奖</option>
            </select>
            <span class="partNum" style="display: none;">预计人数：</span><input class="partNum"  type="text" style="width: 150px;display: none"  id="partNum" >
            </p>			
            <p><span>活动简介：</span>&nbsp;<textarea id="swpContent" style="width: 300px;height: 50px" ></textarea></p>
            <div class="BottomBtn"><input id="save_btn" type="button" value="立即发布" onclick="save()"></div>
        </form>
       </div>
<div id="windowPop" class="hideDiv" style="z-index:240;">
  <div class="closeTop"><strong>奖项设置</strong><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
  <table id="awardDet" class="common_tb" width="100%" cellpadding="0" cellspacing="1" border="0">
  <thead>
  	<tr>
    	<th width="20" ></th>
    	<th >奖品等级</th>
    	<th>奖品详情</th>
    	<th>奖品总数</th>
    	<th>每日发放</th>
    </tr>
    </thead>
    <tbody>
    
    </tbody>
  </table>
  <div class="BottomBtn"><input type="button" value="确定" id="savePrizeLvAndPrize" onclick="savePrizeLvAndPrize();"></div>
</div>
<div id="PopList" class="hideDiv">
  <div class="closeTop"><strong>奖品设置</strong><span id="closeThis"><img src="../images/close.png"></span></div>
  <table id="awardList" class="common_tb" width="100%" cellpadding="0" cellspacing="1" border="0">
  	<thead>
    <tr>
    	<th width="90">奖品编号</th>
    	<th>奖品详情</th>
    	<th width="60">设置</th>
    </tr>
    </thead>
    <tbody>
    
    </tbody>
  </table>
    <div id="prizePage" class="shopPager"></div>
  
</div>
<div id="yinying"></div>
<div class="container" id="container">
  <div class="container_R fr">
      <div class="place">抽奖活动发布</div>
  <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">店面：</span>
        <select id="shopName" onclick="showShopList(1)" disabled="disabled">
        </select>
        <span>活动名称：</span>
        <input type="text" id="searchSwName" class="absoluteTxt">
        <span>提交人：</span>
        <input type="text"  id="searchMan" class="absoluteTxt"></p>
     	<p><input class="btn" id="research" name="查询" type="button" value="查询" onClick="findSweepstakesList()" style="float:right;margin-right:12px;" ></p>
      </div>
       <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="rewardList">
    	<caption><strong>抽奖活动列表       <span id="sup">共0条</span> </strong> <input type="button" onclick="toAdd()" class="common_btn" value="增加"></caption>
    	<thead>
    	<tr>
    		<th>店面</th>
    		<th>活动名称</th>
        	<th>活动图片</th>
        	<th>活动起始日期</th>
        	<th>活动截止日期</th>
        	<th>抽奖类型</th>
        	<th>提交人</th>
        	<th>提交日期</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
       
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
  <div id="pager"></div>
  </div>
    <div class="fc"></div>
  
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(3,1);
</script>


</body>
<!-- InstanceEnd -->
</html>